package org.example.fastproject.core.bean;

import org.example.fastproject.web.sys.model.vo.user.UserLoginVo;
import org.example.fastproject.web.sys.model.vo.user.UserVo;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author 王海舟
 * @Date 2023/1/16 12:32
 * @PackageName:org.example.fastproject.core.bean
 * @ClassName: UserInfo
 * @Description: 用户登录信息
 * @Version 1.0
 */

public class SysUserDetails implements UserDetails {
    private UserVo user;

    private List<String> permissions;

    private Date date;

    public SysUserDetails(UserVo user,List<String> permissions){
        this.user = user;
        this.permissions=permissions;
        this.date = new Date();
    }

    public Long getId(){
        return user.getId();
    }

    public String getName(){
        return user.getName();
    }

    public Date getDate(){
        return date;
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return permissions.stream().map(permission ->{
            return new SimpleGrantedAuthority(permission);
        }).collect(Collectors.toList());
    }

    @Override
    public String getPassword() {
        return user.getPassword();
    }

    @Override
    public String getUsername() {
        return user.getName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }
}
